package registry

import (
	consulregistry "github.com/go-kratos/kratos/contrib/registry/consul/v2"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/go-kratos/kratos/v2/registry"
	"github.com/google/wire"
	consul "github.com/hashicorp/consul/api"
	"kratos-demo-layout/internal/conf"
)

// ProviderSet is server providers.
var ProviderSet = wire.NewSet(NewRegistry)

func NewRegistry(confService *conf.Service, logger log.Logger) registry.Registrar {
	//根据配置生成consul注册实例
	cfg := &consul.Config{
		Address: confService.RegAddr,
	}
	client, err := consul.NewClient(cfg)
	if err != nil {
		log.NewHelper(logger).Error(err)
		panic(err)
	}
	r := consulregistry.New(client)
	return r
}
